package com.qn.example.controller;

import com.qn.example.pojo.Orders;
import com.qn.example.pojo.Page;
import com.qn.example.pojo.R;
import com.qn.example.service.OrderService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

/**
 * @author 21276
 * @version 1.0
 * @date 2023/5/24 14:13
 */
@RestController
@RequestMapping("/order")
public class OrdersController {

    @Resource
    private OrderService orderService;

    @PostMapping("/submit")
    public R submit(@RequestBody Orders order , HttpSession session){
        //1. 得到当前登陆者
        Long userId = (Long) session.getAttribute("user");
        //2. 给订单补全信息
        order.setUserId(userId);
        //交service去下单
        orderService.add(order);
        return  R.success("下单成功");
    }

    @GetMapping("/userPage")
    public R userPage(@RequestParam(value = "page",defaultValue = "1") Integer page,
                      @RequestParam(value = "pageSize",defaultValue = "5") Integer pageSize){
        Page pageBean = orderService.findByPage(page,pageSize);
        return  R.success(pageBean);
    }
}
